from typing import List


class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        i = 0
        j = len(nums) - 1
        index = j
        res = [float('inf')] * (len(nums))
        while i <= j:
            if abs(nums[i]) < abs(nums[j]):
                res[index] = nums[j] ** 2
                j -= 1
            else:
                res[index] = nums[i] ** 2
                i += 1
            index -= 1
        return res
